package mammuthus.client

import java.util
import scala.collection.JavaConversions._

/**
 * Created by fbj on 15-2-4 上午10:42.
 */
class Path() {
  private var detail: util.List[String] = null
  private var split: String = "/"



  def this(path: String) = {

    this()
    val arr = path.split("/+")
    detail = new util.ArrayList[String]()
    for (p <- arr) {
      if (p != null && !p.isEmpty) {
        detail.add(p)
      }
    }
  }

  def getDetail: util.List[String] = {
    return detail
  }

  def setDetail(detail: util.List[String]) {
    this.detail = detail
  }

  def getParentPath: Path = {
    if (detail == null) {
      return null
    }
    val path: Path = new Path()
    if (detail.size > 1) {
      path.setDetail(detail.subList(0, detail.size - 1))
    }
    return path
  }

  def getPathString: String = {
    if (detail == null) {
      return split
    }
    val r: StringBuilder = new StringBuilder
    import scala.collection.JavaConversions._
    for (p <- detail) {
      if (p != null && !p.isEmpty) r.append(split).append(p)
    }
    return r.toString
  }

  def getName: String = {
    if (detail == null) {
      return split
    }
    return detail.get(detail.size - 1)
  }


  def main(args: Array[String]) {
    val p: Path = new Path("/video/_index/pid")
    System.out.println(p.getPathString)
    System.out.println(p.getParentPath.getPathString)
    System.out.println(p.getPathString)
  }

}
